#include <iostream>
#include <cstring>
using namespace std;

//加法运算符重载  双目运算符重载时， 形参是运算符的右操作符
class String {
    public:
        String(const char * str = NULL);
        String operator+(const String &str);
        void show();
    private:
        char *str;    
};
String::String(const char * str) {
    if (str == NULL) {
        this->str = NULL;
    } else {
        int len = strlen(str) + 1;
        this->str = new char[len];
        strcpy(this->str, str);
    }
}
String String::operator+(const String &s) {
    if (!s.str) {
        cout << "error, str is empty!" <<endl;

    }
    int len = strlen(this->str) + strlen(s.str) + 1;
    char *temp;
    temp = new char[len];
    strcpy(temp, this->str);
    strcat(temp, s.str);
    return temp;

}
void String::show() {
    cout << this->str << endl;
}

int main(int argc, char const *argv[])
{
    String s1("hello");
    String s2 = s1 + String("world");
    s2.show();
    return 0;
}
